Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
Is it possible to get an "inverse" function of a Boolean function in javascript?

I was looking to write an "all-or-nothing" function over an array. One approach is, of course, to leverage Array.prototype.every and do something like

function allOrNothing(arr, f, fInv) {
  return arr.every(f) || arr.every(fInv);
}

where f and fInv are indicator functions, and fInv is an "inverse" function of f. For example, if f = (x) => x != null, then fInv = (x) => x == null.

This leads me to think: is it possible to get the function fInv from f?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This function, given a function f as an input, returns its boolean inverse:

let invert = (f) => (x) => !f(x)

e.g.

let invert = (f) => (x) => !f(x)

let eq_five = (x) => x == 5
let neq_five = invert(eq_five)

console.log(eq_five(5)) // true
console.log(neq_five(5)) // false

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!